//
//  ZLExciseBeginFooterView.m
//  ZLExamination
//
//  Created by leilei on 2017/9/3.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZLExciseBeginFooterView.h"

@implementation ZLExciseBeginFooterView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.leftBtn];
        [self addSubview:self.rightBtn];
        [self addSubview:self.sheetBtn];
    }
    return self;
}

#pragma mark - 按钮实现方法
- (void)btnClickAction:(UIButton *)sender {
    if (sender == _leftBtn) {
        if (_leftClick) {
            _leftClick();
        }
    } else if (sender == _rightBtn) {
        if (_rightClick) {
            _rightClick();
        }
    } else if (sender == _sheetBtn) {
        if (_sheetClick) {
            _sheetClick();
        }
    }
}

#pragma mark - 布局
- (void)layoutSubviews
{
    [super layoutSubviews];
    [_leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(30);
        make.left.mas_equalTo(13);
        make.top.mas_equalTo(12);
    }];
    
    [_rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(30);
        make.right.mas_equalTo(-13);
        make.top.mas_equalTo(12);
    }];
    
    [_sheetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(55);
        make.centerX.equalTo(self);
        make.centerY.equalTo(_leftBtn.mas_centerY);
    }];
}

#pragma mark - lazy load
- (UIButton *)leftBtn {
    if (!_leftBtn) {
        _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_leftBtn setImage:kIMAGE(@"exam_left") forState:UIControlStateNormal];
        [_leftBtn addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftBtn;
}

- (UIButton *)rightBtn {
    if (!_rightBtn) {
        _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_rightBtn setImage:kIMAGE(@"exam_right") forState:UIControlStateNormal];
        [_rightBtn addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightBtn;
}

- (UIButton *)sheetBtn {
    if (!_sheetBtn) {
        _sheetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _sheetBtn.backgroundColor = [UIColor clearColor];
        [_sheetBtn setImage:[UIImage imageNamed:@"答题卡"] forState:UIControlStateNormal];
        [_sheetBtn addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sheetBtn;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
